#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
using namespace std;
vector<vector<int>> matrixBlockSum(vector<vector<int>>& mat, int k) {
    int m = mat.size(), n = mat[0].size();
    vector<vector<int>> bpp(m, vector<int>(n + 1));
    for (int i = 0; i < m; i++) {
        for (int j = 1; j < n + 1; j++) {
            bpp[i][j] = bpp[i][j - 1] + mat[i][j - 1];
        }
    }
    vector<vector<int>> vv(m, vector<int>(n));
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            int x1 = i - k >= 0 ? i - k : 0;
            int x2 = i + k <= m - 1 ? i + k : m - 1;
            int y1 = j - k >= 0 ? j - k : 0;
            int y2 = j + k <= n - 1 ? j + k : n - 1;
            y2++;
            for (int begin = x1; begin <= x2; begin++) {
                vv[i][j] += bpp[begin][y2] - bpp[begin][y1];
            }
        }
    }
    return vv;
}